<script>
	import {
		initSqlite,
	} from '@/localService/index.js';

	import {
		requireConfigByCls
	} from "@/localService/configService.js";
	export default {
		//这里可以获取系统语言
		globalData: {
			lang: 'cn',
			isDbLoaded: false,
			selectListItemData: null,

			thickIndexScreenUnselectList: [],
			ispRstPickerArray: [],

			thickSetting: {}
		},

		onLaunch: function() {
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch')

			// initSqlite().then(res => {
			// 	console.log(res)
			// })
			let _self = this;
			plus.io.getFileInfo({
				filePath: "_doc/amins_mobile.db",
				digestAlgorithm: "md5",
				success: (e) => {
					console.log('getFileInfo success')
					console.log(e);
					initSqlite().then(res => {
						console.log(res);
						getApp().globalData.isDbLoaded = true;
						console.log("res   -------------------   0");
						uni.$emit("dbLoaded", true);
						console.log("res   -------------------   1");
					})
				},
				fail: (e) => {
					_self.moveBaseDbFile();
					console.log('getFileInfo fail')
					console.log(e)

				},
				complete: (e) => {
					console.log('getFileInfo complete')
					console.log(e)
				}
			})
		},
		onShow: function() {
			console.log('App Show')
			this.getGlobalThickSetting();
		},
		onHide: function() {
			console.log('App Hide')
		},

		methods: {
			moveBaseDbFile() {
				console.log('moveBaseDbFile')
				let _self = this;
				plus.io.resolveLocalFileSystemURL(
					"_www/static/amins_mobile.db",
					function(orginDbFileEntry) {
						console.log('resolveLocalFileSystemURL success')
						console.log(orginDbFileEntry);

						plus.io.resolveLocalFileSystemURL(
							"_doc",
							function(entry) {
								if (!entry.isFile) {
									orginDbFileEntry.copyTo(entry, "amins_mobile.db",
										function(e) {
											console.log('moveBaseDbFile  copyTo  ok');
											initSqlite().then(res => {
												console.log(res);
												getApp().globalData.isDbLoaded = true;
												uni.$emit("dbLoaded", true);
											})
										},
										function(e) {
											console.log('moveBaseDbFile  copyTo  fail');
											console.log(e);
										})
								}
							},
							function(e) {
								mui.toast(e.message);
								console.log('moveBaseDbFile  fail');
							})


					},
					/* fail: */
					(e) => {
						console.log('getFileInfo fail')
						console.log(e)
					},
					/* complete: */
					(e) => {
						console.log('getFileInfo complete')
						console.log(e)
					}
				)
			},

			getGlobalThickSetting() {
				let _self = this;
				requireConfigByCls("thick").then(e => {
					console.log("requireConfigByClsApi")
					// _self.thickDataList = e;
					// console.log(e)
					let tempRes = {};

					e.forEach(elem => {
						tempRes[elem.cfg_key] = elem.cfg_value;

						if (elem.cfg_key == "ChkUseTmprCrct" || elem.cfg_key == "ChkMtrClsWrng")
							tempRes[elem.cfg_key] = elem.cfg_value == "True";
					})

					console.log(tempRes)
				
					// ChkMtrClsWrng:right   ChkUseTmprCrct:left
					this.globalData.thickSetting = tempRes;
					
					
					let T = 7;
					let TE = 20;
					// TxtFormulaSus
					let tempForm = this.globalData.thickSetting.TxtFormulaSus;
					// let tempForm = "{T} + {TE}";
					tempForm = tempForm.replace(/{/g, " ")
					tempForm = tempForm.replace(/}/g, " ")
					
					console.log(`APP === ${tempForm}`)
					let re = eval(tempForm);
					re = Math.floor(re * 10) / 10;
					re = re.toFixed(2);
					console.log(`APP === ${T} === ${TE} === ${re}`)
				})
			},
		}
	}
</script>

<style lang="scss">
	:root {
		--page-right-toolbar-width: 60rpx;
	}

	page {
		background: #f6f6f6;
	}

	/*每个页面公共css */
	.page-root {
		position: relative;
		width: 100vw;
		height: 100vh;
	}

	.flex-h {
		display: flex;
		flex-direction: row;
	}

	.flex-v {
		display: flex;
		flex-direction: column;
	}

	// 顶部状态栏
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #0062B0;
	}

	// 右侧工具栏
	// .tool-lay {
	// 	width: 50upx;
	// 	height: calc(100vh - 40upx - var(--status-bar-height));
	// 	padding-top: 20upx;
	// 	padding-bottom: 20upx;
	// 	align-items: center;
	// 	justify-content: space-between;

	// 	.tool-img {
	// 		width: 30upx;
	// 		height: 30upx;
	// 	}
	// }

	// 左侧内容区域
	.content-lay {
		width: calc(100vw - 47upx);
		height: 100%;
	}

	// 状态栏下内容区域
	.content-root {
		width: 100vw;
		// height: 100%;
		// background-color: #DD524D44;
	}
</style>
